package com.csdj.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.csdj.common.enums.AppHttpCodeEnum;
import com.csdj.common.utils.ResponseResult;
import com.csdj.pojo.IvIninvoice;
import com.csdj.service.IvInvoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @author: DengYuChang
 * @date: 2023-08-25 14:48
 * @description:
 */
@RestController
@RequestMapping("/ivInvoice")
public class IvInvoiceController {

    @Autowired
    private IvInvoiceService invoiceService;

    @PostMapping("/count")
    public ResponseResult getCount(@RequestBody IvIninvoice ininvoice) {
        int count = invoiceService.getCount(Integer.parseInt(ininvoice.getStartNo()), Integer.parseInt(ininvoice.getEndNo()));
        if (count > 0) {
            return ResponseResult.errorResult(400, "该发票区间内已有发票入库,请重新输入起始号码或终止号码");
        }
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    @PostMapping("invoiceReportUse")
    public ResponseResult invoiceReportUse(@RequestBody Map<String, String> map) {
        System.out.println(map);
        Map map1 = invoiceService.invoiceReportUse(map);
        System.out.println(map1);
        return ResponseResult.okResult(map1);
    }

    @PostMapping("invoiceReportUse2")
    public ResponseResult invoiceReportUse2(@RequestBody Map<String, String> map) {
        System.out.println(map);
        Page<Map> mapPage = new Page<>(Long.parseLong(map.get("pageNum")), 2);
        Page<Map> pageInfo = invoiceService.invoiceReportUse2(mapPage, map);
        return ResponseResult.okResult(pageInfo);
    }

    @PostMapping("invoiceReportMoneySum1")
    public ResponseResult invoiceReportMoneySum1(@RequestBody Map<String, String> map) {
        System.out.println(map);
        Map map1 = invoiceService.invoiceReportMoneySum1(map);
        return ResponseResult.okResult(map1);
    }

    @PostMapping("invoiceReportMoneySum2")
    public ResponseResult invoiceReportMoneySum2(@RequestBody Map<String, String> map) {
        System.out.println(map);
        List<Map> maps = invoiceService.invoiceReportMoneySum2(map);
        return ResponseResult.okResult(maps);
    }

    @PostMapping("invoiceReportMoneyDetail")
    public ResponseResult invoiceReportMoneyDetail(@RequestBody Map<String, String> map) {
        System.out.println(map);
        Page<Map> mapPage = new Page<>(Long.parseLong(map.get("pageNum")), 2);
        Page<Map> pageInfo = invoiceService.invoiceReportMoneyDetail(mapPage, map);
        return ResponseResult.okResult(pageInfo);
    }





}
